package com.yundasys.lab02springbootstudy.future;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.concurrent.CompletableFuture;

/**
 * @PACKAGE_NAME: com.yundasys.lab02springbootstudy.future
 * @NAME: FutureTask
 * @USER: jiangta
 * @DATE: 2021/12/8
 * @TIME: 1:15 下午
 * @PROJECT_NAME: springboot-labs
 */
@Component
public class FutureTask {


    @Async
    public CompletableFuture<Double> fetchPrice() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
        //if (Math.random() < 0.3) {
            throw new RuntimeException("fetch price failed!");
        //}
        //return CompletableFuture.completedFuture(5 + Math.random() * 20);
    }
}
